package com.jindy.module.transfer.controller;

import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.core.page.TableDataInfo;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.module.transfer.domain.SyTransferT;
import com.jindy.module.transfer.service.ISyTransferTService;
import com.jindy.module.transfer.domain.TransferApprovedResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存调拨Controller
 * 
 * @author jindy
 * @date 2023-04-12
 */
@RestController
@RequestMapping("/module/transfer")
public class SyTransferTController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyTransferTController.class);
    @Autowired
    private ISyTransferTService syTransferTService;

    /**
     * 查询库存调拨列表
     */
//    @PreAuthorize("@ss.hasPermi('module:transfer:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyTransferT syTransferT)
    {
        startPage();
        List<TransferApprovedResult> list = syTransferTService.selectSyTransferTList(syTransferT);
        return getDataTable(list);
    }

    /**
     * 导出库存调拨列表
     */
    @PreAuthorize("@ss.hasPermi('module:transfer:export')")
    @Log(title = "库存调拨", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyTransferT syTransferT)
    {
        List<TransferApprovedResult> list = syTransferTService.selectSyTransferTList(syTransferT);
        ExcelUtil<TransferApprovedResult> util = new ExcelUtil<TransferApprovedResult>(TransferApprovedResult.class);
        util.exportExcel(response, list, "库存调拨数据");
    }

    /**
     * 获取库存调拨详细信息
     */
//    @PreAuthorize("@ss.hasPermi('module:transfer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syTransferTService.selectSyTransferTById(id));
    }

    /**
     * 新增库存调拨
     */
    @PreAuthorize("@ss.hasPermi('module:transfer:add')")
    @Log(title = "库存调拨", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyTransferT syTransferT)
    {
        try {
            return syTransferTService.insertSyTransferT(syTransferT);
        } catch (Exception e) {
            LOGGER.error("新增库存调拨失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改库存调拨
     */
    @PreAuthorize("@ss.hasPermi('module:transfer:edit')")
    @Log(title = "库存调拨", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyTransferT syTransferT)
    {
        try {
            return syTransferTService.updateSyTransferT(syTransferT);
        } catch (Exception e) {
            LOGGER.error("修改库存调拨失败",e);
            return AjaxResult.error("修改库存调拨失败");
        }
    }

    /**
     * 删除库存调拨
     */
    @PreAuthorize("@ss.hasPermi('module:transfer:remove')")
    @Log(title = "库存调拨", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return syTransferTService.deleteSyTransferTByIds(ids);
    }
}
